package com.limh.base.widget

import android.app.Dialog
import android.content.Context
import android.view.LayoutInflater
import android.view.animation.AnimationUtils
import android.view.animation.LinearInterpolator
import android.widget.ImageView
import android.widget.TextView
import com.limh.base.R

/**
 * @function：
 * @author： limh
 * @date： 2018/9/28
 * Copyright @2018 Corpration Name
 */
class LoadingDialog(context: Context) : Dialog(context, R.style.loading_dialog) {

    class Builder(private var context: Context) {

        var msg: String? = null

        fun setMsg(msg: String):Builder {
            this.msg=msg
            return this
        }

        fun create(): LoadingDialog {
            val inflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
            val view = inflater.inflate(R.layout.base_loading_view, null)
            val dialog = LoadingDialog(context)
            msg?.let {
                view.findViewById<TextView>(R.id.txt_msg).text = msg
            }


            val image = view.findViewById<ImageView>(R.id.img_loading)
            val circleAnim = AnimationUtils.loadAnimation(context, R.anim.image_loading_roate)
            circleAnim.interpolator = LinearInterpolator()
            image.startAnimation(circleAnim)
            dialog.setContentView(view)
            return dialog
        }
    }

}